function paddedMap = mapPad(map, radius)
%ensure the map is clockwise, to make sure the cross product works properly
% if(ispolycw(map(:, 1), map(:, 2)))
%     map = flipud(map);
%     flipped = true;
% else
    flipped = false;
% end


%get normalised edges of map
mapEdges1 = diff([map ; map(1, :)]);
mapEdges1 = normr(mapEdges1);

%get other edge from each point
mapEdges2 = -circshift(mapEdges1, [1, 0]);

%cross product to work out what direction to offset
z = zeros(size(mapEdges1, 1), 1);
crossProducts = cross([mapEdges1 z], [mapEdges2 z], 2);
directionModifier = repmat(crossProducts(:, 3), 1, 2);

%calculate offset directions
offsetDirections = (mapEdges1 + mapEdges2).*directionModifier;
offsetDirections = normr(offsetDirections);

%calculate what multipler needs to be applied to make the radius go from
%each edge
perpendicularEdges = [mapEdges1(:, 2) -mapEdges1(:, 1)];
dotProducts = abs(dot(perpendicularEdges, offsetDirections, 2)); %edges and directions are both normalised so this is equivalent to cos
dotProducts = repmat(dotProducts, 1, 2);

offsets = offsetDirections./dotProducts.*radius;

%apply offsets to map
paddedMap = map + offsets;

%reset map so new coordinates correspond to old coordinates
if flipped
    paddedMap = flipud(paddedMap);
end
end